#pragma once

#include <pthread.h>

class LockGuard
{
public:
    LockGuard(pthread_mutex_t *lock) :_mutex(lock)
    {
        pthread_mutex_lock(_mutex);
    }
    ~LockGuard()
    {
        pthread_mutex_unlock(_mutex);
    }
private:
    pthread_mutex_t *_mutex;
};

// or 
class Mutex
{
public:
    Mutex(pthread_mutex_t *lock) :_lock(lock)
    {}
    void Lock()
    {
        pthread_mutex_lock(_lock);
    }
    void Unlock()
    {
        pthread_mutex_unlock(_lock);
    }
    ~Mutex() 
    {}
private:
    pthread_mutex_t *_lock;
};

class LockGuard1
{
public:
    LockGuard1(pthread_mutex_t *lock) :_mutex(lock)
    {
        _mutex.Lock();
    }
    ~LockGuard1()
    {
        _mutex.Unlock();
    }
private:
    Mutex _mutex;
};
